package com.example.newsclient.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.newsclient.R;
import com.leon.lib.settingview.LSettingItem;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 我的界面
 */
public class MineFragment extends Fragment {

    private CircleImageView circle_head;
    private TextView tv_userName;
    private LSettingItem item_money;
    private LSettingItem item_history;
    private LSettingItem item_changePsd;
    private LSettingItem item_setting;
    private LSettingItem item_about;

    /**
     * 临时标记
     * true ：登录
     * false ：未登录
     */
    private boolean loginFlag = false;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_mine, container, false);
        initView(view);


        return view;
    }

    /**
     * 初始化控件
     * @param view
     */
    private void initView(View view) {
        circle_head = (CircleImageView) view.findViewById(R.id.circle_head);
        tv_userName = (TextView) view.findViewById(R.id.tv_userName);
        item_money = (LSettingItem) view.findViewById(R.id.item_money);
        item_history = (LSettingItem) view.findViewById(R.id.item_history);
        item_changePsd = (LSettingItem) view.findViewById(R.id.item_changePsd);
        item_setting = (LSettingItem) view.findViewById(R.id.item_setting);
        item_about = (LSettingItem) view.findViewById(R.id.item_about);

        //点击头像
        circle_head.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //调用系统相册，更换头像
                if(loginFlag){
                    Toast.makeText(getContext(),"换头像",Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(getContext(),"请登录，跳转登录界面",Toast.LENGTH_SHORT).show();
                }
            }
        });

        //注册点击事件
        item_money.setmOnLSettingItemClick(new LSettingItem.OnLSettingItemClick() {
            @Override
            public void click() {
                //点击了钱包
                if(loginFlag){
                    Toast.makeText(getContext(),"钱包",Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(getContext(),"请登录，跳转登录界面",Toast.LENGTH_SHORT).show();
                }
            }
        });
        item_history.setmOnLSettingItemClick(new LSettingItem.OnLSettingItemClick() {
            @Override
            public void click() {
                //点击了浏览记录
                if(loginFlag){
                    Toast.makeText(getContext(),"浏览记录",Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(getContext(),"请登录，跳转登录界面",Toast.LENGTH_SHORT).show();
                }
            }
        });
        item_changePsd.setmOnLSettingItemClick(new LSettingItem.OnLSettingItemClick() {
            @Override
            public void click() {
                //点击了修改密码
                if(loginFlag){
                    Toast.makeText(getContext(),"修改密码",Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(getContext(),"请登录，跳转登录界面",Toast.LENGTH_SHORT).show();
                }
            }
        });
        item_setting.setmOnLSettingItemClick(new LSettingItem.OnLSettingItemClick() {
            @Override
            public void click() {
                //点击了设置
                if(loginFlag){
                    Toast.makeText(getContext(),"设置",Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(getContext(),"请登录，跳转登录界面",Toast.LENGTH_SHORT).show();
                }
            }
        });
        item_about.setmOnLSettingItemClick(new LSettingItem.OnLSettingItemClick() {
            @Override
            public void click() {
                //点击了关于
                if(loginFlag){
                    Toast.makeText(getContext(),"关于",Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(getContext(),"请登录，跳转登录界面",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
